<!--
 * Orienteering Sport Diary Copyright (C) 2009 OSDiary Team
 *
 * This file is part of Orienteering Sport Diary (OSDiary).
 *
 * OSDiary is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see http://www.gnu.org/licenses/.
-->

<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<html>
    <head>
        <title>OSDiary</title>
        <link href="${pageContext.request.contextPath}/css/default.css" rel="stylesheet" type="text/css" />
        <meta content="text/html; charset=utf-8" http-equiv="content-type">
        <script src="${pageContext.request.contextPath}/js/prototype.js" type="text/javascript"></script>
        <script language="JavaScript" src="${pageContext.request.contextPath}/struts/utils.js" type="text/javascript"></script>
        <script language="JavaScript" src="${pageContext.request.contextPath}/struts/xhtml/validation.js" type="text/javascript"></script>
        <sx:head />
    </head>
    <body>

        <script language="javascript">
            <!--
            function emailValid(){
                var email = $('email').getValue();
                new Ajax.Request('mailvalidation.action',{
                    method: 'get',
                    parameters: 'email='+email,
                    onSuccess: function(transport){
                        var div = $('resultDiv');
                        if(transport.responseText.match(/true/))
                            div.innerHTML = "<img src=\"images/green.PNG\"/>";
                        else
                            div.innerHTML = "<img src=\"images/red.PNG\"/>";
                    }
                });
            }

            function validate() {
                new Ajax.Request(
                'validateRegistration.action',
                {
                    method: 'get',
                    parameters: Form.serialize($('form')) + '&struts.enableJSONValidation=true&struts.validateOnly=true',
                    onComplete: postValidation
                }
            );
            }

            function postValidation(request) {
                var form = $('form');

                //clear previous validation errors, if any
                StrutsUtils.clearValidationErrors(form);

                //get errors from response
                var text = request.responseText;
                var errorsObject = StrutsUtils.getValidationErrors(text);
                
                //errorsObject.fieldErrors.repassword.length)
                
                //show errors, if any
                if(errorsObject.fieldErrors) {
                    StrutsUtils.showValidationErrors(form, errorsObject);
                } else {
                    //good to go, regular submit
                    form.submit();
                }
            }
            -->
        </script>

        <jsp:include page="WEB-INF/jspparts/logo.jsp" />

        <div id="content">

            <jsp:include page="WEB-INF/jspparts/sidebar.jsp" />

            <div id="main">
                <div id="welcome" class="post">

                    <s:form action="createProfile" method="post" theme="simple" id="form" onsubmit="validate(); return false">
                        <table>
                            <tr>
                                <td><s:property value="%{getText('email')}"/></td>
                                <td><s:textfield id="email" name="email" onkeyup="emailValid()"/></td>
                                <td><div id="resultDiv" width="15px" height="15px"><img src="images/red.PNG" /></div><td>
                            </tr>
                            <tr id="passwordTr">
                                
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('password')}"/></td>
                                <td><s:password name="password"/></td>
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('repassword')}"/></td>
                                <td><s:password name="repassword"/></td>
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('name')}"/></td>
                                <td><s:textfield name="name"/></td>
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('surname')}"/></td>
                                <td><s:textfield name="surname"/></td>
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('birthDate')}"/></td>
                                <td><sx:datetimepicker name="birthDateString" displayFormat="%{getText('dateFormat')}" /></td>
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('club')}"/></td>
                                <td><s:select list="clubs" name="club"/></td>
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('qual')}"/></td>
                                <td><s:select list="quals" name="qual"/></td>
                            </tr>
                            <tr>
                                <td><s:property value="%{getText('sex')}"/></td>
                                <td><s:select list="sexes" name="sex"/></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><s:submit value="%{getText('register')}"/></td>
                            </tr>
                        </table>
                    </s:form>

                </div>
            </div>
            <div id="extra" style="clear: both;"></div>
        </div>

        <jsp:include page="WEB-INF/jspparts/footer.jsp" />

    </body>
</html>